package com.augurit.common.system.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.entity.OmUserPosition;
import com.augurit.common.system.web.org.form.OmUserPositionForm;

public class OmUserPositionConverter {

	public static void convertToEntity(OmUserPositionForm form, OmUserPosition entity){
		if(form != null && entity != null){
			
			if(form.getUpId() != null)
				entity.setUpId(form.getUpId());
			
			if(form.getPosId() != null)
				entity.setPosId(form.getPosId());
			
			if(form.getUserId() != null)
				entity.setUserId(form.getUserId());
			
			if(form.getIsMain() != null && form.getIsMain().trim().length() > 0)
				entity.setIsMain(form.getIsMain());
		}
	}
	
	public static OmUserPositionForm convertToForm(OmUserPosition entity){
		if(entity != null){
			OmUserPositionForm form = new OmUserPositionForm();

			form.setUpId(entity.getUpId());
			form.setPosId(entity.getPosId());
			form.setUserId(entity.getUserId());
			form.setIsMain(entity.getIsMain());
			return form;
		}else
			return null;
	}
	
	public static List<OmUserPositionForm> convertToForm(List<Object[]> list){
		if(list != null && list.size() > 0){
			List<OmUserPositionForm> result = new ArrayList();
			
			for(Object[] objs : list){
				OmUserPositionForm form = convertToForm((OmUserPosition)objs[0]);
				form.setPosName((String)objs[1]);
				result.add(form);
			}
			
			return result;
		}else
			return null;
	}
}
